UnitsConverterTest = TestCase("Test Units Converter");

UnitsConverterTest.prototype.testSimpleConversion = function(){
	simSpace = {
			minx : 0,
			miny : 0,
			maxx : 100,
			maxy : 100
	};
	screenSpace = {
			minx : 0,
			miny : 0,
			maxx : 100,
			maxy : 100
	};
	converter = new UnitsConverter(simSpace, screenSpace);
	assertCoordinatesEqual({x:0,y:100},converter.convert({x:0,y:0}));
};

UnitsConverterTest.prototype.testOffsetConversion = function(){
	simSpace = {
			minx : 0,
			miny : 0,
			maxx : 100,
			maxy : 100
	};
	screenSpace = {
			minx : 10,
			miny : 10,
			maxx : 110,
			maxy : 110
	};
	converter = new UnitsConverter(simSpace, screenSpace);
	assertCoordinatesEqual({x:10,y:110},converter.convert({x:0,y:0}));
};

UnitsConverterTest.prototype.testOffsetAndScaleConversion = function(){
	simSpace = {
			minx : 0,
			miny : 0,
			maxx : 100,
			maxy : 100
	};
	screenSpace = {
			minx : 10,
			miny : 10,
			maxx : 60,
			maxy : 60
	};
	converter = new UnitsConverter(simSpace, screenSpace);
	assertCoordinatesEqual({x:35,y:35},converter.convert({x:50,y:50}));
};

UnitsConverterTest.prototype.testOnlyUsesWholePixels = function(){
	simSpace = {
			minx : 0,
			miny : 0,
			maxx : 100,
			maxy : 100
	};
	screenSpace = {
			minx : 0,
			miny : 0,
			maxx : 11,
			maxy : 11
	};
	converter = new UnitsConverter(simSpace, screenSpace);
	assertCoordinatesEqual({x:6,y:6},converter.convert({x:50,y:50}));
};

UnitsConverterTest.prototype.testOnlyUsesWholePixelsRoundingDown = function(){
	simSpace = {
			minx : 0,
			miny : 0,
			maxx : 100,
			maxy : 100
	};
	screenSpace = {
			minx : 0,
			miny : 0,
			maxx : 11,
			maxy : 11
	};
	converter = new UnitsConverter(simSpace, screenSpace);
	assertCoordinatesEqual({x:5,y:6},converter.convert({x:42,y:42}));
};

function assertCoordinatesEqual(coordsOne,coordsTwo){
	assertTrue("expected: {x:"+coordsOne.x+",y:"+coordsOne.y+"}; got: {x:"+coordsTwo.x+",y:"+coordsTwo.y+"}",(coordsOne.x == coordsTwo.x) && (coordsOne.y == coordsTwo.y));
}